/*     */ package com.zimbra.cs.dav.resource;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.google.common.collect.Maps;
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.calendar.ICalTimeZone;
/*     */ import com.zimbra.common.calendar.ParsedDateTime;
/*     */ import com.zimbra.common.calendar.TimeZoneMap;
/*     */ import com.zimbra.common.calendar.ZCalendar.ICalTok;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZComponent;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZParameter;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZProperty;
/*     */ import com.zimbra.common.calendar.ZCalendar.ZVCalendar;
/*     */ import com.zimbra.common.localconfig.DebugConfig;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.dav.DavContext;
/*     */ import com.zimbra.cs.dav.DavException;
/*     */ import com.zimbra.cs.dav.caldav.AutoScheduler;
/*     */ import com.zimbra.cs.dav.caldav.Filter;
/*     */ import com.zimbra.cs.dav.caldav.Range.ExpandRange;
/*     */ import com.zimbra.cs.dav.caldav.Range.TimeRange;
/*     */ import com.zimbra.cs.dav.property.CalDavProperty;
/*     */ import com.zimbra.cs.mailbox.CalendarItem;
/*     */ import com.zimbra.cs.mailbox.CalendarItem.CalendarMetadata;
/*     */ import com.zimbra.cs.mailbox.CalendarItem.Instance;
/*     */ import com.zimbra.cs.mailbox.DavNames;
/*     */ import com.zimbra.cs.mailbox.DavNames.DavName;
/*     */ import com.zimbra.cs.mailbox.Flag.FlagInfo;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.mailbox.calendar.InviteInfo;
/*     */ import com.zimbra.cs.mailbox.calendar.RecurId;
/*     */ import com.zimbra.cs.mailbox.calendar.ZAttendee;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.CharArrayWriter;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract interface CalendarObject
/*     */ {
/*     */   public static final String CAL_EXTENSION = ".ics";
/*     */   
/*     */   public abstract String getUid();
/*     */   
/*     */   public abstract boolean match(Filter paramFilter);
/*     */   
/*     */   public abstract String getVcalendar(DavContext paramDavContext, Filter paramFilter)
/*     */     throws IOException, DavException;
/*     */   
/*     */   public abstract void expand(Range.ExpandRange paramExpandRange);
/*     */   
/*     */   public static abstract class LocalCalendarObjectBase
/*     */     extends MailItemResource
/*     */   {
/*     */     public LocalCalendarObjectBase(DavContext ctxt, String path, MailItem item)
/*     */       throws ServiceException
/*     */     {
/*  95 */       super(path, item);
/*     */     }
/*     */     
/*     */     protected static Invite getFixedUpCopy(DavContext ctxt, Invite inv, Account acct, boolean delegated, boolean isScheduleMsg) throws ServiceException
/*     */     {
/* 100 */       if ((ctxt.isIcalClient()) && (!inv.isOrganizer())) {
/* 101 */         Invite copy = inv.newCopy();
/* 102 */         boolean iCal3NeedsReplyProp = false;
/* 103 */         ZAttendee attendee = copy.getMatchingAttendee(acct);
/* 104 */         if (!delegated) {
/* 105 */           if (attendee != null) {
/* 106 */             iCal3NeedsReplyProp = (attendee.hasRsvp()) && (attendee.getRsvp().booleanValue()) && ("NE".equals(attendee.getPartStat()));
/*     */ 
/*     */           }
/*     */           else
/*     */           {
/* 111 */             attendee = new ZAttendee(acct.getName());
/* 112 */             copy.addAttendee(attendee);
/* 113 */             iCal3NeedsReplyProp = true;
/*     */           }
/* 115 */           if ((iCal3NeedsReplyProp) && (isScheduleMsg)) {
/* 116 */             ZCalendar.ZProperty prop = new ZCalendar.ZProperty("X-APPLE-NEEDS-REPLY");
/* 117 */             prop.setValue("TRUE");
/* 118 */             copy.addXProp(prop);
/*     */           }
/*     */         }
/* 121 */         if ((!isScheduleMsg) && (attendee != null))
/*     */         {
/* 123 */           attendee.setRsvp(null);
/*     */         }
/* 125 */         return copy;
/*     */       }
/* 127 */       return inv;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static class CalendarPath
/*     */   {
/*     */     public static String generate(DavContext ctxt, String itemPath, String uid, Integer mailbox_id, Integer item_id, int extra)
/*     */     {
/* 141 */       StringBuilder path = new StringBuilder(parentCollectionPath(ctxt, itemPath));
/* 142 */       DavNames.DavName davName = null;
/* 143 */       if ((DebugConfig.enableDAVclientCanChooseResourceBaseName) && (mailbox_id != null) && (item_id != null)) {
/* 144 */         davName = DavNames.get(mailbox_id.intValue(), item_id.intValue());
/*     */       }
/* 146 */       if (davName != null) {
/* 147 */         if (path.charAt(path.length() - 1) != '/') {
/* 148 */           path.append("/");
/*     */         }
/* 150 */         path.append(davName.davBaseName);
/*     */       } else {
/* 152 */         addBaseNameBasedOnEscapedUID(path, uid, extra);
/*     */       }
/* 154 */       return path.toString();
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */     private static void addBaseNameBasedOnEscapedUID(StringBuilder path, String uid, int extra)
/*     */     {
/* 162 */       if (path.charAt(path.length() - 1) != '/') {
/* 163 */         path.append("/");
/*     */       }
/* 165 */       path.append(uid.replace("/", "//"));
/* 166 */       if (extra >= 0) {
/* 167 */         path.append(",").append(extra);
/*     */       }
/* 169 */       path.append(".ics");
/*     */     }
/*     */     
/*     */     private static String parentCollectionPath(DavContext ctxt, String itemPath) {
/* 173 */       if (ctxt != null) {
/* 174 */         if (ctxt.getCollectionPath() != null) {
/* 175 */           itemPath = ctxt.getCollectionPath();
/* 176 */         } else if (ctxt.getActingAsDelegateFor() != null) {
/* 177 */           itemPath = itemPath + ctxt.getActingAsDelegateFor();
/*     */         }
/*     */       }
/* 180 */       return itemPath;
/*     */     }
/*     */   }
/*     */   
/*     */   public static class ScheduleMessage extends CalendarObject.LocalCalendarObjectBase implements CalendarObject { private final Invite mInvite;
/*     */     
/* 186 */     public ScheduleMessage(DavContext ctxt, String path, String owner, Invite inv, Message msg) throws ServiceException { super(path, msg);
/* 187 */       this.mInvite = inv;
/* 188 */       addProperty(CalDavProperty.getCalendarData(this));
/*     */     }
/*     */     
/* 191 */     public String getUid() { return this.mInvite.getUid(); }
/*     */     
/*     */ 
/* 194 */     public boolean match(Filter filter) { return true; }
/*     */     
/*     */     public String getVcalendar(DavContext ctxt, Filter filter) throws IOException, DavException {
/* 197 */       CharArrayWriter wr = null;
/*     */       try {
/* 199 */         wr = new CharArrayWriter();
/* 200 */         wr.append("BEGIN:VCALENDAR\r\n");
/* 201 */         wr.append("VERSION:").append("2.0").append("\r\n");
/* 202 */         wr.append("PRODID:").append("Zimbra-Calendar-Provider").append("\r\n");
/* 203 */         wr.append("METHOD:").append(this.mInvite.getMethod()).append("\r\n");
/* 204 */         Account acct = ctxt.getAuthAccount();
/* 205 */         allowPrivateAccess = false;
/*     */         try {
/* 207 */           Mailbox mbox = getMailbox(ctxt);
/* 208 */           OperationContext octxt = ctxt.getOperationContext();
/* 209 */           Folder folder = mbox.getFolderById(octxt, this.mFolderId);
/* 210 */           allowPrivateAccess = CalendarItem.allowPrivateAccess(folder, ctxt.getAuthAccount(), octxt.isUsingAdminPrivileges());
/*     */         }
/*     */         catch (ServiceException se) {
/* 213 */           ZimbraLog.dav.warn("cannot determine private access status", se);
/*     */         }
/* 215 */         boolean delegated = !acct.getId().equalsIgnoreCase(this.mOwnerId);
/* 216 */         Invite fixedInv = getFixedUpCopy(ctxt, this.mInvite, acct, delegated, true);
/* 217 */         ZCalendar.ZComponent comp = fixedInv.newToVComponent(false, allowPrivateAccess);
/* 218 */         if ((filter == null) || (filter.match(comp)))
/* 219 */           comp.toICalendar(wr, true);
/* 220 */         wr.append("END:VCALENDAR\r\n");
/* 221 */         wr.flush();
/* 222 */         return wr.toString();
/*     */       } catch (ServiceException se) { boolean allowPrivateAccess;
/* 224 */         ZimbraLog.dav.warn("cannot convert to iCalendar", se);
/* 225 */         return "";
/*     */       } finally {
/* 227 */         if (wr != null)
/* 228 */           wr.close();
/*     */       }
/*     */     }
/*     */     
/*     */     public InputStream getContent(DavContext ctxt) throws IOException, DavException {
/* 233 */       return new ByteArrayInputStream(getVcalendar(ctxt, null).getBytes("UTF-8"));
/*     */     }
/*     */     
/*     */     public boolean isCollection() {
/* 237 */       return false;
/*     */     }
/*     */     
/*     */     public void delete(DavContext ctxt) throws DavException {
/*     */       try {
/* 242 */         Mailbox mbox = getMailbox(ctxt);
/* 243 */         if (mbox.getAccount().isPrefDeleteInviteOnReply()) {
/* 244 */           super.delete(ctxt);
/*     */         } else {
/* 246 */           mbox.alterTag(ctxt.getOperationContext(), this.mId, MailItem.Type.MESSAGE, Flag.FlagInfo.UNREAD, false, null);
/*     */         }
/*     */       } catch (ServiceException se) {
/* 249 */         int resCode = (se instanceof MailServiceException.NoSuchItemException) ? 404 : 403;
/*     */         
/* 251 */         throw new DavException("cannot delete item", resCode, se);
/*     */       }
/*     */     }
/*     */     
/*     */     public void expand(Range.ExpandRange range) {}
/*     */   }
/*     */   
/*     */   public static class LightWeightCalendarObject extends DavResource implements CalendarObject
/*     */   {
/*     */     private final int mMailboxId;
/*     */     private final int mId;
/*     */     private final String mUid;
/*     */     private final String mEtag;
/*     */     private final long mStart;
/*     */     private final long mEnd;
/*     */     
/*     */     public LightWeightCalendarObject(String path, String owner, CalendarItem.CalendarMetadata data) {
/* 268 */       super(owner);
/* 269 */       this.mMailboxId = data.mailboxId;
/* 270 */       this.mId = data.itemId;
/* 271 */       this.mUid = data.uid;
/* 272 */       this.mStart = data.start_time;
/* 273 */       this.mEnd = data.end_time;
/* 274 */       this.mEtag = MailItemResource.getEtag(Integer.toString(data.mod_metadata), Integer.toString(data.mod_content));
/* 275 */       setProperty("getetag", this.mEtag);
/* 276 */       addProperty(CalDavProperty.getCalendarData(this));
/*     */     }
/*     */     
/* 279 */     public String getUid() { return this.mUid; }
/*     */     
/*     */     public boolean match(Filter filter) {
/* 282 */       Range.TimeRange range = filter.getTimeRange();
/* 283 */       if (range == null)
/* 284 */         return true;
/* 285 */       return range.matches(this.mMailboxId, this.mId, this.mStart, this.mEnd);
/*     */     }
/*     */     
/* 288 */     public String getEtag() { return this.mEtag; }
/*     */     
/*     */     public String getVcalendar(DavContext ctxt, Filter filter) throws IOException, DavException {
/* 291 */       ZimbraLog.dav.debug("constructing full resource");
/* 292 */       return getFullResource(ctxt).getVcalendar(ctxt, filter);
/*     */     }
/*     */     
/* 295 */     public InputStream getContent(DavContext ctxt) throws IOException, DavException { return new ByteArrayInputStream(getVcalendar(ctxt, null).getBytes("UTF-8")); }
/*     */     
/*     */ 
/* 298 */     public boolean isCollection() { return false; }
/*     */     
/*     */     public void delete(DavContext ctxt) throws DavException
/*     */     {}
/*     */     
/* 303 */     private CalendarObject getFullResource(DavContext ctxt) throws DavException { String user = null;
/* 304 */       Account acct = ctxt.getOperationContext().getAuthenticatedUser();
/* 305 */       if (acct != null)
/* 306 */         user = acct.getName();
/*     */       try {
/* 308 */         DavResource rs = UrlNamespace.getResourceByItemId(ctxt, user, this.mId);
/* 309 */         if ((rs instanceof CalendarObject.LocalCalendarObject)) {
/* 310 */           return (CalendarObject.LocalCalendarObject)rs;
/*     */         }
/* 312 */         throw new DavException("not a calendar item", 400);
/*     */       } catch (ServiceException se) {
/* 314 */         throw new DavException("can't fetch item", se);
/*     */       }
/*     */     }
/*     */     
/* 318 */     public boolean hasContent(DavContext ctxt) { return true; }
/*     */     
/*     */     public void expand(Range.ExpandRange range) {}
/*     */   }
/*     */   
/*     */   public static class LocalCalendarObject extends CalendarObject.LocalCalendarObjectBase implements CalendarObject { private final CalendarItem item;
/*     */     private final String mUid;
/*     */     private Invite[] mInvites;
/*     */     
/* 327 */     public LocalCalendarObject(DavContext ctxt, CalendarItem calItem) throws ServiceException { this(ctxt, calItem, false); }
/*     */     
/*     */     public LocalCalendarObject(DavContext ctxt, CalendarItem calItem, boolean newItem) throws ServiceException
/*     */     {
/* 331 */       this(ctxt, CalendarObject.CalendarPath.generate(ctxt, calItem.getPath(), calItem.getUid(), Integer.valueOf(calItem.getMailboxId()), Integer.valueOf(calItem.getId()), -1), calItem);
/*     */       
/* 333 */       this.mNewlyCreated = newItem;
/*     */     }
/*     */     
/*     */     public LocalCalendarObject(DavContext ctxt, String path, CalendarItem calItem) throws ServiceException {
/* 337 */       super(path, calItem);
/* 338 */       this.item = calItem;
/* 339 */       this.mUid = calItem.getUid();
/* 340 */       this.mInvites = calItem.getInvites();
/* 341 */       this.mTzmap = calItem.getTimeZoneMap();
/* 342 */       Invite defInv = calItem.getDefaultInviteOrNull();
/* 343 */       if (defInv != null)
/* 344 */         setProperty("displayname", defInv.getName());
/* 345 */       setProperty("getcontenttype", "text/calendar");
/* 346 */       setProperty("getcontentlength", Long.toString(calItem.getSize()));
/* 347 */       addProperty(CalDavProperty.getCalendarData(this));
/* 348 */       if ((this.mInvites[0].hasRecurId()) && (this.mInvites.length > 1))
/*     */       {
/* 350 */         ArrayList<Invite> newList = new ArrayList();
/* 351 */         ArrayList<Invite> exceptions = new ArrayList();
/* 352 */         for (Invite i : this.mInvites) {
/* 353 */           if (i.hasRecurId()) {
/* 354 */             exceptions.add(i);
/*     */           } else
/* 356 */             newList.add(i);
/*     */         }
/* 358 */         newList.addAll(exceptions);
/* 359 */         this.mInvites = ((Invite[])newList.toArray(new Invite[0]));
/*     */       }
/* 361 */       this.mMailboxId = calItem.getMailboxId();
/* 362 */       this.mStart = calItem.getStartTime();
/* 363 */       this.mEnd = calItem.getEndTime();
/*     */     }
/*     */     
/*     */ 
/*     */     private final TimeZoneMap mTzmap;
/*     */     
/*     */     private final int mMailboxId;
/*     */     
/*     */     private final long mStart;
/*     */     
/*     */     private final long mEnd;
/*     */     public boolean match(Filter filter)
/*     */     {
/* 376 */       Range.TimeRange range = filter.getTimeRange();
/* 377 */       if ((range != null) && (!range.matches(this.mMailboxId, this.mId, this.mStart, this.mEnd)))
/* 378 */         return false;
/* 379 */       for (Invite inv : this.mInvites) {
/*     */         try {
/* 381 */           ZCalendar.ZComponent vcomp = inv.newToVComponent(false, false);
/* 382 */           if (filter.match(vcomp))
/* 383 */             return true;
/*     */         } catch (ServiceException se) {
/* 385 */           ZimbraLog.dav.warn("cannot convert to ICalendar", se);
/*     */         }
/*     */       }
/*     */       
/*     */ 
/* 390 */       return false;
/*     */     }
/*     */     
/*     */     private ZCalendar.ZVCalendar createZVcalendar(List<ZCalendar.ZComponent> components, Map<String, ICalTimeZone> oldIdsToNewTZsMap) {
/* 394 */       Set<String> usedOldIds = Sets.newHashSet();
/* 395 */       for (ZCalendar.ZComponent comp : components)
/* 396 */         for (ZCalendar.ZProperty prop : comp.getProperties()) {
/* 397 */           ZCalendar.ZParameter tzidParam = prop.getParameter(ZCalendar.ICalTok.TZID);
/* 398 */           if (tzidParam != null)
/*     */           {
/*     */ 
/* 401 */             String tzid = tzidParam.getValue();
/* 402 */             if (tzid != null) {
/* 403 */               ICalTimeZone newTZ = (ICalTimeZone)oldIdsToNewTZsMap.get(tzid);
/* 404 */               if (newTZ != null)
/*     */               {
/*     */ 
/* 407 */                 usedOldIds.add(tzid);
/* 408 */                 tzidParam.setValue(newTZ.getID());
/*     */               }
/*     */             }
/*     */           } }
/* 412 */       ZCalendar.ZVCalendar vcal = new ZCalendar.ZVCalendar();
/* 413 */       vcal.addVersionAndProdId();
/* 414 */       for (Map.Entry<String, ICalTimeZone> entry : oldIdsToNewTZsMap.entrySet()) {
/* 415 */         if (usedOldIds.contains(entry.getKey())) {
/* 416 */           vcal.addComponent(((ICalTimeZone)entry.getValue()).newToVTimeZone());
/*     */         }
/*     */       }
/* 419 */       for (ZCalendar.ZComponent comp : components) {
/* 420 */         vcal.addComponent(comp);
/*     */       }
/* 422 */       return vcal;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */     public ZCalendar.ZVCalendar getZVcalendar(DavContext ctxt, Filter filter)
/*     */       throws ServiceException, DavException
/*     */     {
/* 430 */       Map<String, ICalTimeZone> oldIdsToNewTZsMap = Maps.newHashMap();
/* 431 */       List<ZCalendar.ZComponent> components = Lists.newArrayList();
/* 432 */       Iterator<ICalTimeZone> iter = this.mTzmap.tzIterator();
/* 433 */       while (iter.hasNext()) {
/* 434 */         ICalTimeZone tz = (ICalTimeZone)iter.next();
/* 435 */         String oldId = tz.getID();
/* 436 */         ICalTimeZone wellKnownTZ = ICalTimeZone.lookupMatchingWellKnownTZ(tz);
/* 437 */         oldIdsToNewTZsMap.put(oldId, wellKnownTZ);
/*     */       }
/* 439 */       Account acct = ctxt.getAuthAccount();
/* 440 */       boolean allowPrivateAccess = false;
/*     */       try {
/* 442 */         Mailbox mbox = getMailbox(ctxt);
/* 443 */         OperationContext octxt = ctxt.getOperationContext();
/* 444 */         Folder folder = mbox.getFolderById(octxt, this.mFolderId);
/* 445 */         allowPrivateAccess = CalendarItem.allowPrivateAccess(folder, ctxt.getAuthAccount(), octxt.isUsingAdminPrivileges());
/*     */       }
/*     */       catch (ServiceException se) {
/* 448 */         ZimbraLog.dav.warn("cannot determine private access status", se);
/*     */       }
/* 450 */       boolean delegated = !acct.getId().equalsIgnoreCase(this.mOwnerId);
/* 451 */       if (!LC.calendar_apple_ical_compatible_canceled_instances.booleanValue()) {
/* 452 */         for (Invite inv : this.mInvites) {
/* 453 */           Invite fixedInv = getFixedUpCopy(ctxt, inv, acct, delegated, false);
/* 454 */           ZCalendar.ZComponent vcomp = fixedInv.newToVComponent(false, allowPrivateAccess);
/* 455 */           if ((filter == null) || (filter.match(vcomp))) {
/* 456 */             components.add(vcomp);
/*     */           }
/*     */         }
/*     */       } else {
/* 460 */         Invite[] fixedInvs = new Invite[this.mInvites.length];
/* 461 */         for (int i = 0; i < this.mInvites.length; i++) {
/* 462 */           fixedInvs[i] = getFixedUpCopy(ctxt, this.mInvites[i], acct, delegated, false);
/*     */         }
/* 464 */         boolean appleICalExdateHack = LC.calendar_apple_ical_compatible_canceled_instances.booleanValue();
/* 465 */         ZCalendar.ZComponent[] vcomps = Invite.toVComponents(fixedInvs, allowPrivateAccess, false, appleICalExdateHack);
/* 466 */         if (vcomps != null) {
/* 467 */           for (ZCalendar.ZComponent vcomp : vcomps) {
/* 468 */             if ((filter == null) || (filter.match(vcomp))) {
/* 469 */               components.add(vcomp);
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/* 474 */       return createZVcalendar(components, oldIdsToNewTZsMap);
/*     */     }
/*     */     
/*     */     public String getVcalendar(DavContext ctxt, Filter filter) throws IOException, DavException
/*     */     {
/*     */       try
/*     */       {
/* 481 */         CharArrayWriter writer = new CharArrayWriter();Throwable localThrowable2 = null;
/* 482 */         try { ZCalendar.ZVCalendar vcal = getZVcalendar(ctxt, filter);
/* 483 */           vcal.toICalendar(writer, true);
/* 484 */           writer.flush();
/* 485 */           return writer.toString();
/*     */         }
/*     */         catch (Throwable localThrowable1)
/*     */         {
/* 481 */           localThrowable2 = localThrowable1;throw localThrowable1;
/*     */ 
/*     */         }
/*     */         finally
/*     */         {
/* 486 */           if (writer != null) if (localThrowable2 != null) try { writer.close(); } catch (Throwable x2) { localThrowable2.addSuppressed(x2); } else writer.close();
/*     */         }
/* 488 */         return "";
/*     */       }
/*     */       catch (ServiceException se)
/*     */       {
/* 487 */         ZimbraLog.dav.warn("cannot convert to iCalendar", se);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     public void delete(DavContext ctxt)
/*     */       throws DavException
/*     */     {
/* 498 */       Provisioning prov = Provisioning.getInstance();
/* 499 */       String user = ctxt.getUser();
/*     */       try
/*     */       {
/* 502 */         Account account = prov.get(Key.AccountBy.name, user);
/* 503 */         Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
/* 504 */         if (this.mInvites != null) {
/* 505 */           AutoScheduler autoScheduler = AutoScheduler.getAutoScheduler(mbox, getMailbox(ctxt), this.mInvites, this.mId, ctxt);
/*     */           
/* 507 */           if (autoScheduler != null) {
/* 508 */             autoScheduler.doSchedulingActions();
/*     */           }
/*     */         }
/*     */       } catch (ServiceException e) {
/* 512 */         ZimbraLog.dav.debug("Unexpected exception during autoscheduling for delete of %s", this.mUri, e);
/*     */       }
/* 514 */       super.delete(ctxt);
/*     */     }
/*     */     
/*     */     public InputStream getContent(DavContext ctxt) throws IOException, DavException
/*     */     {
/* 519 */       return new ByteArrayInputStream(getVcalendar(ctxt, null).getBytes("UTF-8"));
/*     */     }
/*     */     
/*     */     public boolean isCollection()
/*     */     {
/* 524 */       return false;
/*     */     }
/*     */     
/*     */     public String getUid()
/*     */     {
/* 529 */       return this.mUid;
/*     */     }
/*     */     
/*     */     public boolean hasContent(DavContext ctxt)
/*     */     {
/* 534 */       return true;
/*     */     }
/*     */     
/*     */     public void expand(Range.ExpandRange range)
/*     */     {
/* 539 */       if (!this.item.isRecurring())
/* 540 */         return;
/* 541 */       Invite defInvite = this.item.getDefaultInviteOrNull();
/* 542 */       if (defInvite == null)
/* 543 */         return;
/* 544 */       ArrayList<Invite> inviteList = new ArrayList();
/*     */       try {
/* 546 */         for (CalendarItem.Instance instance : this.item.expandInstances(range.getStart(), range.getEnd(), false)) {
/* 547 */           InviteInfo info = instance.getInviteInfo();
/* 548 */           Invite inv = this.item.getInvite(info.getMsgId(), info.getComponentId());
/* 549 */           if (!instance.isException())
/*     */           {
/* 551 */             ParsedDateTime datetime = RecurId.createFromInstance(instance).getDt();
/* 552 */             if (defInvite.isAllDayEvent()) {
/* 553 */               datetime.forceDateOnly();
/*     */             } else {
/* 555 */               ParsedDateTime defStart = defInvite.getStartTime();
/* 556 */               if ((defStart != null) && (defStart.getTimeZone() != null))
/* 557 */                 datetime.toTimeZone(defInvite.getStartTime().getTimeZone());
/*     */             }
/* 559 */             inv = inv.makeInstanceInvite(datetime);
/*     */           }
/* 561 */           inviteList.add(inv);
/*     */         }
/* 563 */         this.mInvites = ((Invite[])inviteList.toArray(new Invite[0]));
/*     */       } catch (ServiceException se) {
/* 565 */         ZimbraLog.dav.warn("error getting calendar item " + this.mUid + " from mailbox " + this.mMailboxId, se);
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/resource/CalendarObject.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */